﻿using UnityEngine;
using System.Collections;
using Newtonsoft.Json;

public class GameObjectViewer : MonoBehaviour {
	public GameObject SelectedObject;
	public string s_Json;

	void Start(){

	}

	void OnGUI(){
		Ray GOVRay = new Ray(this.transform.position,this.transform.forward);
		RaycastHit GOVRayCastHit;
		if(Physics.Raycast(GOVRay, out GOVRayCastHit)){
			if(GOVRayCastHit.collider.gameObject.name == "Col"){
				SelectedObject = GOVRayCastHit.collider.gameObject.transform.parent.gameObject;
			}
		}
		if(SelectedObject){
			if(SelectedObject.GetComponent<BaseFile>()){
				s_Json = JsonConvert.SerializeObject(SelectedObject.GetComponent<BaseFile>());
				print (""+s_Json);
				GUI.Label(new Rect(0,0,Screen.width,Screen.height),s_Json);
			}
		}


	}
}
